{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8fc3d4e1",
   "metadata": {},
   "source": [
    "* 课本作业"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e6fd271d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d85e2b7d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "Don't panic!\n"
     ]
    }
   ],
   "source": [
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d6312345",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Ford Prefect', 'Male', 'Researcher', 'Betelgeuse Seven']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    ">>> person1 = ['Ford Prefect','Male','Researcher','Betelgeuse Seven']\n",
    ">>> person1\n",
    "['Ford Prefect','Male','Researcher','Betelgeuse Seven']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3e45fedf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Name',\n",
       " 'Ford Prefect',\n",
       " 'Gender',\n",
       " 'Male',\n",
       " 'Occupation',\n",
       " 'Researcher',\n",
       " 'Home Planet',\n",
       " 'Betelgeuse Seven']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    ">>> person2 = ['Name','Ford Prefect','Gender','Male','Occupation','Researcher','Home Planet','Betelgeuse Seven']\n",
    ">>> person2\n",
    "['Name','Ford Prefect','Gender','Male','Occupation','Researcher','Home Planet','Betelgeuse Seven']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a4e27d8",
   "metadata": {},
   "source": [
    "* 剩下的reverse..回去练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "91e0e74a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4, 3, 2, 1]\n"
     ]
    }
   ],
   "source": [
    "lista = [1,2,3,4]\n",
    "lista.reverse()\n",
    "print(lista)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fbeeec42",
   "metadata": {},
   "source": [
    "(1)extend函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fe6933f8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6]\n",
      "[['a', 'b'], 'c', 'd', 'e', 'f']\n"
     ]
    }
   ],
   "source": [
    "A = [1,2,3]\n",
    "B = [['a','b']]\n",
    "A.extend([4])\n",
    "A.extend([5,6])\n",
    "B.extend(['c','d'])\n",
    "B.extend(['e','f'])\n",
    "print(A)\n",
    "print(B)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "78a0e169",
   "metadata": {},
   "source": [
    "(2)clear函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ac55ad26",
   "metadata": {},
   "outputs": [],
   "source": [
    "mixs = ['python','1',(1,),{'name':'dawei'}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f0dbfc9f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['python', '1', (1,), {'name': 'dawei'}] 4\n"
     ]
    }
   ],
   "source": [
    "print(mixs,len(mixs))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6473c8f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "mixs.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8825f82d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[] 0\n"
     ]
    }
   ],
   "source": [
    "print(mixs,len(mixs))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "884433c9",
   "metadata": {},
   "source": [
    "(3)copy函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9868f0dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a = [0, 2, 3, ['a', 'b', 'c'], 5]\n",
      "b = [0, 2, 3, ['a', 'b', 'c'], 5]\n",
      "c = [1, 2, 3, ['a', 'b', 'c']]\n",
      "d = [1, 2, 3, ['a', 'b']]\n"
     ]
    }
   ],
   "source": [
    "import copy\n",
    "a = [1,2,3,['a','b']]  #原始对象\n",
    "\n",
    "b = a         #赋值，传对象的引用\n",
    "c = copy.copy(a)   #对象拷贝，浅拷贝\n",
    "d = copy.deepcopy(a)    #对象拷贝，深拷贝\n",
    "\n",
    "a[0]=0\n",
    "a.append(5)    #修改对象a \n",
    "a[3].append('c')    #修改对象a中的['a','b']数组对象\n",
    "\n",
    "\n",
    "print('a =',a)\n",
    "print('b =',b)\n",
    "print('c =',c)\n",
    "print('d =',d)\n",
    "  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd078c52",
   "metadata": {},
   "source": [
    "(3)sort函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "fa54f90b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('AB', 'abd', 253), ('AZ', 'abc', 154), ('BZ', 'aac', 144)]\n"
     ]
    }
   ],
   "source": [
    "a = [('AZ','abc',154),('BZ','aac',144),('AB','abd',253)]\n",
    "\n",
    "a.sort()\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60075a66",
   "metadata": {},
   "source": [
    "* 列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "fd16169a",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (613523197.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [22]\u001b[1;36m\u001b[0m\n\u001b[1;33m    | 一个普通标题 | 一个普通标题 | 一个普通标题 |\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "\n",
    "| 一个普通标题 | 一个普通标题 | 一个普通标题 |\n",
    "| ------- | -------- | -------- |\n",
    "| 短文本 | 中等文本 | 稍微长一点的文本\n",
    "| 稍微长一点的文本 | 短文本 |  中等文本 |\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "4410182f",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (4119126954.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [23]\u001b[1;36m\u001b[0m\n\u001b[1;33m    |  表头  |  表头  |\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "|  表头  |  表头  |\n",
    "|  ---   |  ---   |\n",
    "|  单元格|  单元格 |\n",
    "|  单元格|  单元格 |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "d3af455b",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (2510013758.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [24]\u001b[1;36m\u001b[0m\n\u001b[1;33m    - | :-: | :-:\u001b[0m\n\u001b[1;37m      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "\n",
    "Name | Academy | score\n",
    "- | :-: | :-:\n",
    "Harry Potter | Gryffindor| 90\n",
    "Hermione Granger | Gryffindor | 100\n",
    "Draco Malfoy | Slytherin | 90\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d76447f1",
   "metadata": {},
   "source": [
    " * 1.append() -------- 向列表的尾部添加元素\n",
    " * 2.insert(index，object) -------- 向指定的下标处添加元素\n",
    " * 3.sort（）-------- 进行排序（从下到大 int类型）可以对字母进行排序（ASCII值）类型不能混\n",
    " * 4.index（）-------- 返回的是元素在列表中的第一个位置\n",
    " * 5.reverse（）------------ 将列表进行翻转\n",
    " * 6.remove（）---------- 删除某个元素，如果有重复，删除的是第一次出现的元素，如果元素不存在会 报错\n",
    " * 7.count（）-------- 返回的是某个元素在列表里面的个数\n",
    "* 8.clear（）--------- 清除元素\n",
    "* 9.copy（）-------- 浅拷贝对象 不等价与 =\n",
    "* 10.extend（）-------- 合并列表\n",
    "* 11.pop（）-------删除列表尾部的元素（与append相反）,返回删除的元素，pop(i) i指的是下标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "59fd329b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
